<template>
	<view class="content" ref="homeRef">
		<view v-for="(item,index) in homePageInfo.items" :key="index">
			<component :is="'my-'+item.type"></component>
		</view>
		
	</view>
</template>

<script>
	import MySearch from '../../components/my-search.vue'
	import MyVideo from '../../components/my-video.vue'
	import MyNotice from '../../components/my-notice.vue'
	import MyNavBar from '../../components/my-navbar.vue'
	import MyBanner from '../../components/my-banner.vue'
	import MyImage from '../../components/my-image.vue'
	import MyWindow from '../../components/my-window.vue'
	import MyGoods from '../../components/my-goods.vue'
	export default {
		components:{MySearch,MyVideo,MyNotice,MyNavBar,MyBanner,MyImage,MyWindow,MyGoods},
		data() {
			return {
				// 首页的数据
				homePageInfo:{},
				// 首页标题
				title:'',
				// 首页标题栏的字体颜色
				frontColor:'',
				// 首页标题栏的背景颜色
				backgroundColor:'',
				// comps:['my-image','my-goods','my-window','my-swiper','my-navbar','my-search','my-notice','my-video'],
			}
		},
		async created() {
			await this.getPageInfo()
			// console.log(this.title,this.frontColor,this.backgroundColor)
			uni.setNavigationBarTitle({
				title:this.title
			})
			uni.setNavigationBarColor({
				backgroundColor:this.backgroundColor,
				frontColor:"#ffffff"
			})
			// this.comps.forEach(item => {
			// 	console.log(`<${item}></${item}>`)
			// 	this.$refs.homeRef.innerHTML += `<${item}></${item}>`
			// })
			// console.log(this.$refs.homeRef)
		},
		mounted(){
			
		},
		methods: {
			async getPageInfo(){
				const {status,data} = await this.$http.get('page/detail&pageId=0')
				console.log(JSON.parse(JSON.stringify(data)))
				if (status !== 200) return this.$msg()
				this.homePageInfo = data.pageData
				this.title = data.pageData.page.params.title
				this.backgroundColor = data.pageData.page.style.titleBackgroundColor
				if(data.pageData.page.style.titleTextColor === 'white'){
					this.frontColor = "#ffffff"
				} else{
					this.frontColor = "#000000"
				}
				this.$store.commit('home/setComponentInfo',data.pageData.items)
				return true
			}
		}
	}
</script>

<style>
	
</style>
